/*** 
 * @_______________#########_______________________ 
 * @______________############_____________________ 
 * @______________#############____________________ 
 * @_____________##__###########___________________ 
 * @____________###__######_#####__________________ 
 * @____________###_#######___####_________________ 
 * @___________###__##########_####________________ 
 * @__________####__###########_####_______________ 
 * @________#####___###########__#####_____________ 
 * @_______######___###_########___#####___________ 
 * @_______#####___###___########___######_________ 
 * @______######___###__###########___######_______ 
 * @_____######___####_##############__######______ 
 * @____#######__#####################_#######_____ 
 * @____#######__##############################____ 
 * @___#######__######_#################_#######___ 
 * @___#######__######_######_#########___######___ 
 * @___#######____##__######___######_____######___ 
 * @___#######________######____#####_____#####____ 
 * @____######________#####_____#####_____####_____ 
 * @_____#####________####______#####_____###______ 
 * @______#####______;###________###______#________ 
 * @________##_______####________####______________ 
 * @
 * @Author: ipk518 121206530@qq.com
 * @Date: 2025-03-06 20:00:55
 * @LastEditors: ipk518 121206530@qq.com
 * @LastEditTime: 2025-04-22 17:22:14
 * @FilePath: /etws-sxk2307/Middlewares/dataTransmission/webTop/tcpSession.h
 * @Description: 
 * @************佛祖保佑************
 * @Copyright (c) 2025 by etws@quyujiang, All Rights Reserved. 
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../../inc/commHeader.h"

using namespace std;

class tcpSock{

protected:
	tcpSock();
	const tcpSock &operator=(const tcpSock &single) = delete;
	tcpSock(const tcpSock &single) = delete;
	~tcpSock();
public:
	
	

	static tcpSock& Instance();

	void Init(const char *nIp,int nPort);

	int CreateSocket();

	int Close();

	size_t Send( unsigned char* pBuf, size_t nLen, size_t msg) const;

	
	int Receive(char* pBuf, size_t nLen) const;

	void Register(CallbackCmdFun callbackFn);

	int sendto(struct cmdDataType* cmd,uint8_t * cmdData);

    size_t sendto(uint8_t* data,size_t len);

	char m_ip[20];
	int m_sock;
	int m_port;
	int m_disconnect;
	int m_darktsFlag = 1;

private:
	bool         m_bEventLoopStarted;
	pthread_t    m_tid;
	static void*  EventLoop(void* lpParameter );
	void ProcessEvent();
	char tcpBuf[1024];

	CallbackCmdFun CmdFun = NULL;/*指令用户空间回调函数*/
};